﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Bussines.Utils;
using Entities;

namespace Website.Administrator
{
    public partial class Login : System.Web.UI.Page
    {
        readonly NguoiDungService nsdService = new NguoiDungService();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var nsd = new NguoiDung { Tendangnhap = txtTenDangNhap.Text, Matkhau = Utils.HashMD5(txtMatKhau.Text) };
            var loginStatus = nsdService.checkLogin(nsd);
            if (loginStatus.Equals(Constants.LOGIN_SUCCESS))
            {
                MessageBox.Show(Constants.LOGIN_SUCCESS_MSG, "Default.aspx");
            }
            else if (loginStatus.Equals(Constants.LOGIN_USER_NOT_EXIST))
            {
                if (Request.UrlReferrer != null)
                    MessageBox.Show(Constants.LOGIN_USER_NOT_EXIST_MSG, Request.UrlReferrer.ToString());
            }
            else if (loginStatus.Equals(Constants.LOGIN_PASSWORD_MISMATCH))
                if (Request.UrlReferrer != null)
                    MessageBox.Show(Constants.LOGIN_PASSWORD_MISMATCH_MSG, Request.UrlReferrer.ToString());
        }

        protected void btnExit_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Default.aspx");
        }
    }
}